package com.platform.modules.order;

import com.platform.modules.mall.entity.MallGoodsEntity;
import com.platform.modules.mall.entity.MallOrderEntity;
import com.platform.modules.mall.entity.MallOrderGoodsEntity;
import com.platform.modules.mall.entity.MallUserEntity;

import java.util.List;

public abstract class AbsOrderBuild<T extends InitParams> implements IOrderBuild {

    public T initParams;
    protected ParamsEntity params;
    protected MallUserEntity user;

    public MallOrderEntity getOrderEntity() {
        return orderEntity;
    }

    protected MallOrderEntity orderEntity;

    public void init(T initParams) {
        this.initParams = initParams;
        this.params = initParams.getParams();
        this.user = initParams.getLoginUser();
    }

    @Override
    public MallOrderEntity orderInfo(MallGoodsEntity goods) {
        return orderEntity = OrderUtil.getOrder(goods, params, user);
    }

    public List<MallOrderGoodsEntity> orderGoods(MallGoodsEntity entity) {
        orderEntity.setOrderGoodsEntityList(OrderUtil.goodsToOrderGoodsList(params,orderEntity,entity));
        return orderEntity.getOrderGoodsEntityList();
    }

}
